<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Parking extends Model
{
    protected $table='park_parkings';
    protected $guarded=[];
    public $timestamps=false;
    
    public function isFree()
    {
        return $this->attributes['type'] == 1;
    }
    public function isPrivate()
    {
        return $this->attributes['type'] == 2;
    }
    public function isNewEnergy()
    {
        return $this->attributes['type'] == 3;
    }
    
    public function getTypeTextAttribute()
    {
        switch ($this->attributes['type']){
            case 1:return 'free';
            case 2:return 'private';
            case 3:return 'charge';
            default:return 'free';
        }
    }
    
    public function getTypeTextChineseAttribute()
    {
        switch ($this->attributes['type']){
            case 1:return '免费车位';
            case 2:return '私家车位';
            case 3:return '充电车位';
            default:return '免费车位';
        }
    }
    
    public function record()
    {
        return $this->hasOne(Record::class,'Parklot','id')->where('ParkStatus',1);
    }
    
    public function user()
    {
        return $this->belongsTo(Member::class,'user_id','uid');
    }
    

}
